import Vue from 'vue'
import VueRouter from 'vue-router'
// import Cookies from 'js-cookie'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'login',
        component: () => import('@/views/login')
    },
    {
        path: '/main',
        name: 'main',
        component: () => import('@/views/main/Main'),
        redirect: '/home',
        children: [
            {
                path: '/home',
                name: 'home',
                component: () => import('@/views/home')
            },
            {
                path: '/a',
                name: 'a',
                component: () => import('@/views/componentTest/a')
            },
            {
                path: '/personInfo',
                name: 'personInfo',
                component: () => import('@/views/personInfo/index1')
            },
            {
                path: '/novel',
                name: 'novel',
                component: () => import('@/views/novel/index')
            },
            {
                path: '/video',
                name: 'video',
                component: () => import('@/views/video/index')
            },
            {
                path: '/role',
                name: 'role',
                component: () => import('@/views/role/index')
            },
            {
                path: '/roleAuth',
                name: 'roleAuth',
                component: () => import('@/views/role/authUser')
            },
            {
                path: '/One',
                name: 'One',
                component: () => import('@/views/componentTest/One')
            },
            {
                path: '/Two',
                name: 'Two',
                component: () => import('@/views/componentTest/Two')
            },
            {
                path: '/Brother',
                name: 'Brother',
                component: () => import('@/views/componentTest/Two')
            },
            {
                path: '/Children',
                name: 'Children',
                component: () => import('@/views/componentTest/Two')
            },
            {
                path: '/user',
                name: 'user',
                component: () => import('@/views/user/index')
            },
            {
                path: '/menuTree',
                name: 'menuTree',
                component: () => import('@/components/system/menu/index')
            },
            {
                path: '/guo',
                name: 'guo',
                component: () => import('@/test/guo')
            }
        ]
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
    return VueRouterPush.call(this, to).catch((err) => err)
}
// router.beforeEach((to,from,next)=>{
//     if (!Cookies.get("token") && to.name != "login"){
//         next({
//             name: "login",
//             query: to.query
//         })
//     } else {
//         next();
//     }
// })

export default router
